package org.custom.spring.boot.transaction.service.transactional;

import org.custom.spring.boot.transaction.entity.Transaction;
import org.custom.spring.boot.transaction.mapper.TransactionMapper;
import org.custom.spring.boot.transaction.utils.ValidUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 用于辅助的transaction服务
 *
 * @author LiKun
 * @date 2021/9/10 16:30
 */
@Service
public class AssistService {
    @Resource
    private TransactionMapper transactionMapper;

    @Transactional
    public int withTransaction(String data) {
        return transactionMapper.insert(Transaction.getInstance(data));
    }

    public int withoutTransaction(String data) {
        return transactionMapper.insert(Transaction.getInstance(data));
    }

    @Transactional
    public int withTransactionException(String data) {
        transactionMapper.insert(Transaction.getInstance(data));
        return ValidUtil.byZero();
    }

    public int withoutTransactionException(String data) {
        transactionMapper.insert(Transaction.getInstance(data));
        return ValidUtil.byZero();
    }
}
